define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'shopro/group/check/index' + location.search,
                    add_url: 'shopro/group/check/add',
                    edit_url: 'shopro/group/check/edit',
                    del_url: 'shopro/group/check/del',
                    multi_url: 'shopro/group/check/multi',
                    import_url: 'shopro/group/check/import',
                    table: 'shopro_group_identity',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [

                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'nickname', title: '用户昵称'},
                        {field: 'member_type', title: '团长类型',operate:false,searchList: {"3":'',"1":'官审',"2":'非官审'}, formatter: Table.api.formatter.normal},
                        {field: 'level', title: '团长等级',operate:false,searchList: {"3":'小小团长',"1":'大团长',"2":'小团长'}, formatter: Table.api.formatter.normal},
                        {field: 'ext', title: '备注'},
                        {field: 'status', title: '状态',searchList: {"0":'待审核',"1":'已审核',"2":'冻结中'}, formatter: Table.api.formatter.normal},
                        {field: 'createtime', title: '申请时间', operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'verificationtime', title: '通过时间', operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.buttons,
                            buttons: [

                                {
                                    name: 'ajax',
                                    text: '审核',
                                    title: '审核',
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: '',
                                    hidden:function (row){
                                        return false;
                                    },
                                    disable:function (row){
                                        if (row.status==1){
                                            return true;
                                        }
                                    },
                                    url: 'shopro/group/check/collection_status/type/1',
                                    confirm:function(row){
                                        return '确定通过大团长的申请吗';
                                    },
                                    success: function (data, ret) {
                                        Layer.alert(ret.msg);
                                        table.bootstrapTable('refresh');
                                        //如果需要阻止成功提示，则必须使用return false;
                                        //return false;
                                    },
                                    error: function (data, ret) {
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                },
                                // {
                                //     name: 'ajax',
                                //     text: '冻结',
                                //     title: '冻结',
                                //     classname: 'btn btn-xs btn-success btn-ajax btn-restoreit',
                                //     icon: '',
                                //     hidden:function (row){
                                //         return false;
                                //     },
                                //     disable:function (row){
                                //         if (row.status==2){
                                //             return true;
                                //         }
                                //     },
                                //     url: 'shopro/group/check/collection_status/type/2',
                                //     confirm:function(row){
                                //         return '确定冻结大团长状态吗';
                                //     },
                                //     success: function (data, ret) {
                                //         Layer.alert(ret.msg);
                                //         table.bootstrapTable('refresh');
                                //         //如果需要阻止成功提示，则必须使用return false;
                                //         //return false;
                                //     },
                                //     error: function (data, ret) {
                                //         Layer.alert(ret.msg);
                                //         return false;
                                //     }
                                // },

                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
